Skip to content

Fix IllegalArgumentException in DamageIndicatedItemFluidContainer.canDrain on empty container#219

Merged
rubensworks merged 2 commits intomaster-1.21from
copilot/fix-damage-indicated-item-fluid-container
Mar 6, 2026
Merged

Fix IllegalArgumentException in DamageIndicatedItemFluidContainer.canDrain on empty container#219
rubensworks merged 2 commits intomaster-1.21from
copilot/fix-damage-indicated-item-fluid-container

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

NeoForge 21.11.38-beta+ throws IllegalArgumentException when extract is called with an empty FluidResource. canDrain was unconditionally passing fluidHandler.getResource(0) to extract, which is an empty resource when the container holds no fluid.

Change

  • In canDrain, extract the resource before opening the transaction and short-circuit with false if resource.isEmpty() — mirroring the fix applied downstream in EvilCraft's ItemBloodContainer, but at the base class level so all subclasses benefit.
// Before
try (var tx = Transaction.openRoot()) {
    int simulatedDrain = fluidHandler.extract(fluidHandler.getResource(0), amount, tx);
    return simulatedDrain == amount;
}

// After
FluidResource resource = fluidHandler.getResource(0);
if (resource.isEmpty()) return false;  // extract() rejects empty resources
try (var tx = Transaction.openRoot()) {
    int simulatedDrain = fluidHandler.extract(resource, amount, tx);
    return simulatedDrain == amount;
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.puppycrawl.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-2e0d869fa8235758/dbs/java/working/files-to-index7661378451342775573.list --sourceArchiveDir=/tmp/codeql-scratch-2e0d869fa8235758/dbs/java/src --outputDir=/tmp/codeql-scratch-2e0d869fa8235758/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…idContainer

Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue in DamageIndicatedItemFluidContainer Fix IllegalArgumentException in DamageIndicatedItemFluidContainer.canDrain on empty container Mar 6, 2026
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 6, 2026

@coveralls
Copy link

coveralls commented Mar 6, 2026

Coverage Status

coverage: 30.805% (-0.008%) from 30.813%
when pulling d7ab45a on copilot/fix-damage-indicated-item-fluid-container
into 1616828 on master-1.21.

@rubensworks rubensworks marked this pull request as ready for review March 6, 2026 19:31
@rubensworks rubensworks merged commit e1a085f into master-1.21 Mar 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants